<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>flatMap</title>
</head>

<body>
  <script>
    let phrases = ['hello world', 'the definitive guide']

    let words = phrases.flatMap(phrases => phrases.split(' '))
    let words1 = phrases.map(phrases => phrases.split(' '))
    console.log(words);
    console.log(words1.flat());


    let a = [-1, -5, 1, 2]
    let b = a.map(x => x < 0 ? [] : x)
    let b1 = a.flatMap(x => x < 0 ? [] : x)
    console.log(b);
    console.log(b1);
  </script>
</body>

</html>